﻿using Abp.Domain.Uow;
using Abp.Runtime.Caching;
using Abp.Web.Models;
using apbmvc.companys;
using apbmvc.companys.Dto;
using apbmvc.Web.Signalrs;
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace apbmvc.Web.Controllers
{
    public class HomeController : apbmvcControllerBase
    {

        private readonly ICompanyAppService _icompanyservice;
        private readonly ICacheManager _cacheManager;


        public HomeController(ICompanyAppService icompanyservice, ICacheManager cacheManager)
        {
            _icompanyservice = icompanyservice;
            _cacheManager = cacheManager;
        }

       // [UnitOfWork]
        public async Task<ActionResult> Index()
        {
            Logger.Debug("Controller  my name is debug");
            Logger.Error("Controller  my name is debug");
            Logger.Warn("Controller  my name is debug");

          var ddddd=   _icompanyservice.GetTsAsync("select * from companies");


            //var model = new companyDto();
            //model.comname = "上海市棋至文化传播有限公司";
            //model.comnameshort = Guid.NewGuid().ToString();
            //model.natureid = 15;
            //await _icompanyservice.Addcompany(model);


            var data = await _icompanyservice.GetCompanies();


            int d = 1;

            return View();
        }




        [DontWrapResult] //取消abp json格式
        public async Task<JsonResult> AAA()
        {
            _cacheManager.GetCache("AAA").Clear();


            var ms =await _cacheManager.GetCache("AAA").Get("all", () =>_icompanyservice.GetCompanies());


            return Json(ms, JsonRequestBehavior.AllowGet);

        }



        public ActionResult SignalrsDemo()
        {
            ViewBag.ClientName = "聊客-" + Guid.NewGuid().ToString("N");
            var onLineUserList = ChatHub.OnLineUsers.Select(u => new SelectListItem() { Text = u.Value, Value = u.Key }).ToList();
            onLineUserList.Insert(0, new SelectListItem() { Text = "-所有人-", Value = "" });
            ViewBag.OnLineUsers = onLineUserList;
            return View();
        }
	}
}